/**
 * note
 * not tested on opera
 */
if (typeof inweo.utils.thread == "undefined") {
	inweo.utils.thread = new Class({
		id		: null,
		data	: null,
		time	: 300,
		pauseIt	: false,
		object	: null,
		initialize: function() {},
		start: function(callback, data, time) {			
			this.time = time || this.time;
			this.data = data || null;
			var self = this;
			this.id = setInterval(function() {
				if (inweo.threads[self.id].pauseIt == true) {
					return;
				}
				callback.call(inweo.threads[self.id]);
			}, this.time);
			inweo.threads[this.id] = this;
			return this.id;
		},
		stop: function() {
			clearInterval(this.id);
		},
		pause: function() {
			this.pauseIt = true;
		},
		resume: function() {
			this.pauseIt = false;			
		},
		run: function(callback) {
			var siv = setInterval(function() {
				callback.call(null);
				clearInterval(siv);
			}, 0);
		},
		__messageCallback: function(message, data) {
			if ($type(this.func) == "function") {
				this.func.call(this, message, data);
			}
		},
		messageCallback: function(func) {
			this.func = func;
		}
	});
	inweo.utils.threadManager = new Class({
		initialize: function() {
			if (inweo.get("inweo.utils.threadManager") != true) {
				inweo.set("inweo.utils.threadManager", true);
				inweo.utils.threadManager	= this;
				window.inweo.threads		= [];
			}
			return inweo.utils.threadManager;
		},
		thread: function(id) {
			return inweo.threads[id];
		},
		stopAll: function() {
			inweo.threads.each(function(thread) {
				thread.stop();
			});
		},
		pauseAll: function() {
			inweo.threads.each(function(thread) {
				thread.pause();
			});
		},
		resumeAll: function() {
			inweo.threads.each(function(thread) {
				thread.resume();
			});
		}
	});
	new inweo.utils.threadManager();
}